/*=========================================================================

Program:   Virtual Surgery
Language:  C++
Date:      2009-9-1
Version:   0.1
Mail:		   nelfylee@gmail.com

Copyright (c) 2009 Nelfy Lee. All rights reserved.

=========================================================================*/
#ifndef _PIPELINE_MODEL_H_
#define _PIPELINE_MODEL_H_

#include <QStandardItemModel>
#include <QStandardItem>
#include <QMetatype>

#include "Source.h"

class Source;
class QString;
class DisplayModel;

//extern enum SourceType;
// enum DisplayMode;
//extern enum SourceProperty;

class PipelineModel : public QAbstractItemModel
{
	Q_OBJECT

public:
	PipelineModel(QObject *parent=0);
	~PipelineModel();

	QVariant data(const QModelIndex &index, int role) const;
	Qt::ItemFlags flags(const QModelIndex &index) const;
	QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
	QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
	QModelIndex parent(const QModelIndex &child) const;
	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	int columnCount(const QModelIndex &parent = QModelIndex()) const;
	QStandardItem* itemFromIndex(const QModelIndex&) const;



private:
	friend class Source;
	QStandardItem *m_rootItem;
	DisplayModel *m_displayModel;
	QIcon *m_iconVolume;
	QIcon *m_iconSurface;
	QIcon *m_iconStarOn;
	QIcon *m_iconStarOff;
	//bool m_isDisplaying2D;
	
public:
	int getFreeSubID();

	void addSource(Source *source);
	void removeSource(Source *source);
	void removeSource(const QModelIndex&);
	void setBaseSource(const QModelIndex&);
	void createSurfaceSource(const QModelIndex&);
	Source* sourceFromIndex(const QModelIndex&) const;
	QModelIndex indexFromSource(Source*) const;
	void setDisplayModel(DisplayModel*);

	SourceType sourceType(const QModelIndex&) const;

	// invoked by source
	void propertyChanged(Source*, SourceProperty);		


public slots:
	void slotUpdate();

signals:
	void emitSourceAdded(const QModelIndex&);
	void emitSourcePreRemove(const QModelIndex&);
	void emitSetBase(const QModelIndex&);
	void emitPropertyChanged(Source*, SourceProperty);
	void emitSourceSelected(const QModelIndex&);


private:
	void sourceAdded(Source*);
};




#endif

